package com.example.asus.broadcast;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class IntentReceiverActivity extends AppCompatActivity {
    private Button myButton = null;
    private Button msm = null;
    private final String nobody ="Who.care.the.name";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent_receiver);

        myButton = (Button) findViewById(R.id.myButton);
        //为按钮对象设置监听器对象
        myButton.setOnClickListener(new MyButtonListener());

        msm = (Button)findViewById(R.id.sms);
        msm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(IntentReceiverActivity.this,IntentReceiverInJavaActivity.class);
                startActivity(intent);
            }
        });
    }

    class MyButtonListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            //生成一个Intent对象
            Intent intent = new Intent(nobody);
            //在Intent对象当中添加一个键值对
            intent.putExtra("testIntent", "Test！");
            sendBroadcast(intent);
        }
    }
}
